package top.hidoctor.auscultation.adapter;

import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.tang.net.NetClient;
import com.tang.util.TimeUtil;

import java.util.List;

import top.hidoctor.auscultation.R;
import top.hidoctor.auscultation.bean.PatientsBean;
import top.hidoctor.auscultation.utils.BirthdayToAgeUtil;
import top.hidoctor.auscultation.widget.GlideCircleTransform;

public class PatientAdapter extends BaseQuickAdapter<PatientsBean.ResultBean> {
    public PatientAdapter(int layoutResId, List<PatientsBean.ResultBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, PatientsBean.ResultBean item) {
        helper.setText(R.id.tv_jianhu, (item.getBirthday() == null ? " " : BirthdayToAgeUtil.BirthdayToAge(TimeUtil.formatTime(item.getBirthday(), TimeUtil.Y_M_D))) + " | " + item.getGuardian());
        helper.setText(R.id.tv_name, TextUtils.isEmpty(item.getName()) ? "" : item.getName());
        helper.setText(R.id.tv_phone, TextUtils.isEmpty(item.getPhone()) ? "" : item.getPhone());
        RequestOptions optionsCircle = new RequestOptions();
        DrawableTransitionOptions transitionOptions = new DrawableTransitionOptions();
        Glide.with(mContext)
                .load(NetClient.IMG_URL + item.getAvatar())
                .apply(optionsCircle.transform(new GlideCircleTransform()).placeholder(R.drawable.ic_avater_zw))
                .transition(transitionOptions.crossFade())
                .into((ImageView) helper.getView(R.id.iv_avater));

        String lastTime = item.getLastTime();
        if (lastTime.contains("新数据")) {
            helper.setText(R.id.tv_news, lastTime);
            helper.getView(R.id.tv_content).setVisibility(View.GONE);
            helper.setBackgroundColor(R.id.tv_news, Color.parseColor("#6E99BF"));
        } else {
            helper.setBackgroundColor(R.id.tv_news, Color.parseColor("#0F88F2"));
            helper.getView(R.id.tv_content).setVisibility(View.VISIBLE);
            helper.setText(R.id.tv_news, "新数据");
            helper.setText(R.id.tv_content, lastTime + "日内");
        }
    }
}
